//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "fn_targetShot.sqf"
#include <core_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_target","_selectionName","_damage","_shooter","_time"];
DEFAULT_PARAM(_target,0,objNull);
DEFAULT_PARAM(_selectionName,1,"");
DEFAULT_PARAM(_damage,2,0);
DEFAULT_PARAM(_shooter,3,objNull);

if (IS_OBJECT(_target) && _selectionName == "" && {_damage >= 0.005} && {!isnull _target} && {_target getVariable["IsUp",true]}) then {
	TRACE_1("Target Shot",_target);
	_target setVariable["IsUp",false];
	_target animate["terc", 1];
	
	_up_time = (time - (_target getVariable["UpTime",0]));
	if (GVAR(AVERAGE_UP_TIME) <= 0) then { GVAR(AVERAGE_UP_TIME) = _up_time; };
	GVAR(AVERAGE_UP_TIME) = (GVAR(AVERAGE_UP_TIME) + _up_time) / 2;
	
	if (!isnull (_shooter) && {isplayer _shooter}) then {
		TRACE_1("Score",_shooter);
		["addScore",[_shooter,1]] call FUNC(callEvent);
	};
} else {
	TRACE_1("Not enough damage",_target);
};

TRACE("End");
TMFPROFILERSTOP;
0